package WEB.Servlet;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import WEB.Servlet.Actions.ActionFactory;
import WEB.Servlet.Actions.Action;


public class AuthorisationServlet extends HttpServlet {

     protected ActionFactory factory = new ActionFactory();

     public AuthorisationServlet() {
          super();
     }

     protected String getActionName(HttpServletRequest request) {
          String path = request.getServletPath();
          try
          {
              int index = path.lastIndexOf(".");
              return path.substring(1,index);
          }
          catch(IndexOutOfBoundsException e)
          {
              return "";  
          }
     }

     public void service(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
          Action action = factory.create(getActionName(request));
              String url = action.perform(request, response);
              if (url != null)
              {
                   getServletContext().getRequestDispatcher(url).forward(request, response);
              }
                //response.sendRedirect("http://...");     }
     }
}